<?php

namespace Frieza\Modules\Photo\Extensions;

use Encore\Admin\Admin;

class RemoveRow
{
    protected $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

    protected function script()
    {
        return <<<SCRIPT

$('.operate-remove').on('click', function () {
    var _this = $(this);
    let noteId = $(this).data('id');
    let type = 'remove';
    
    layer.prompt({title: '移除话题', formType: 2}, function(msg, index){
        let params = {note_id:noteId, type:type, extra_msg: msg}

        $.post(url, params , function (e) {
            if(e.code == 1) {
                _this.addClass('hidden');
                toastr.success(e.msg, null, {
                    timeOut : 1000
                });
                layer.close(index);
            } else {
                toastr.error(e.msg, null, {
                    timeOut : 1000
                });
            }
        });
    });
});

SCRIPT;
    }

    public function render()
    {
        Admin::script($this->script());

        return "<a class='btn btn-xs btn-success fa fa-check operate-remove' data-id='{$this->id}'>移除话题</a>";
    }

    public function __toString()
    {
        return $this->render();
    }
}
